import {Injectable} from '@angular/core';
import {BaseService} from '../../../core/service/base.service';
import {_HttpClient} from '@delon/theme';
import {Observable} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class DeviceInspectionPlanService extends BaseService {

  getUrl(): string {
    return 'api/device-inspection-plan';
  }

  constructor(http: _HttpClient) {
    super(http);
  }


  generaTask(templateId: string): Observable<any> {
    const url = `${this.getUrl() + '/gener-inspection-task'}?templateId=${templateId}`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object templateId=${templateId}`)),
      catchError(this.handleError<any>(`getany templateId=${templateId}`)),
    );
  }

  planItems(planId: string): Observable<any> {
    const url = `${this.getUrl() + '/plan-items'}?planId=${planId}`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object planId=${planId}`)),
      catchError(this.handleError<any>(`getany planId=${planId}`)),
    );
  }
}
